package com.browse.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.browse.config.CustomerShardingAlgorithm;
import com.browse.service.BrowseRecordService;
import com.common.domain.po.VideoBrowseRecord;
import com.common.domain.vo.BrowseRecordListByPageVO;
import com.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author 路亚
 * @version 0.1
 * @className BrowseRecordController
 * @description
 * @date 2024/12/26 17:33
 * @since jdk11
 */
@RestController
@RequestMapping("/browse/record")
@Slf4j
@Api(tags = "浏览记录管理")
@RequiredArgsConstructor
public class BrowseRecordController {

    private final BrowseRecordService browseRecordService;

    @GetMapping("/listByPage")
    @ApiOperation("分页查询浏览记录")
    public Result listByPage(Integer page){
        BrowseRecordListByPageVO result = browseRecordService.listByPage(page);
        return Result.success(result);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("删除浏览记录")
    public Result deleteById(Long id){
        QueryWrapper<VideoBrowseRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        queryWrapper.le("view_time", LocalDateTime.now());
        browseRecordService.remove(queryWrapper);
        return Result.success();
    }

}
